import torch

M = torch.tensor([[[1, 2, 3], [4, 5, 6]],
                  [[7, 8, 9], [10, 11, 12]]])
print(M.shape)
print(M[:, -1, :])

# 创建两个矩阵
matrix_a = torch.tensor([[1, 2], [3, 4]], dtype=torch.float32)
matrix_b = torch.tensor([[5, 6], [7, 8]], dtype=torch.float32)

print(torch.tensor([[3], [3]], dtype=torch.float32).shape)
print(matrix_a + torch.tensor([[3], [3]], dtype=torch.float32))
print(matrix_a.exp())
print(matrix_b.exp())

print(matrix_a.sum(0, True))
print(matrix_a.sum(0, False))
#print(matrix_a.sum(2, True))
print(matrix_a.min(1, True).values)

matrix_c = torch.tensor([1, 2], dtype=torch.float32)
print(matrix_c.shape)
print(matrix_c)
print(matrix_a * matrix_c)

matrix_d = torch.tensor([[1, 2], [3, 4], [5, 6]], dtype=torch.float32)
print(matrix_d.view(6, 1))
# 创建一个二维张量
tensor_2d = torch.randn(4, 6)
print("原始二维张量:")
print(tensor_2d)
print("形状:", tensor_2d.shape)

# 使用 view 函数将二维张量转换为 2x3x4 的三维张量
tensor_3d = tensor_2d.view(2, 3, 4)
print("\n转换后的三维张量:")
print(tensor_3d)
print("形状:", tensor_3d.shape)